<template>
  <div id="aCoursesList" class="bg-fa of">
        <div class="mt40">
          <!-- /无数据提示 开始-->
          <section class="no-data-wrap" v-if="data.total == 0">
            <em class="icon30 no-data-ico">&nbsp;</em>
            <span class="c-666 fsize14 ml10 vam"
            >没有购买课程...</span
            >
          </section>
          <!-- /无数据提示 结束-->
          <!-- 数据列表 开始-->
          <article v-if="data.total > 0" class="comm-course-list">
            <ul id="bna" class="of">
              <li v-for="item in data.items" :key="item.id">
                <div class="cc-l-wrap">
                  <section class="course-img">
                    <img
                      :src="item.courseCover"
                      class="img-responsive"
                      alt="课程封面"
                    />
                    <div class="cc-mask">
                      <a
                        :href="'/course/' + item.courseId"
                        title="开始学习"
                        class="comm-btn c-btn-1"
                      >开始学习</a
                      >
                    </div>
                  </section>
                  <h3 class="hLh30 txtOf mt10">
                    <a
                      :href="'/course/' + item.courseId"
                      :title="item.courseTitle"
                      class="course-title fsize18 c-333"
                    >{{ item.courseTitle }}</a
                    >
                  </h3>
                  <section class="mt10 hLh20 of">
                    <span
                      v-if="Number(item.totalFee) !== 0"
                      class="fr jgTag bg-green"
                    >
                      <i class="c-fff fsize12 f-fA">{{ item.totalFee }}元</i>
                    </span>
                    <span
                      v-else
                      class="fr jgTag bg-green"
                    >
                      <i class="c-fff fsize12 f-fA">免费</i>
                    </span>
                  </section>
                </div>
              </li>
            </ul>
            <div class="clear" />
          </article>
          <!-- /数据列表 结束-->
        </div>
        <div>
          <div class="paging">
            <!-- undisable这个class是否存在，取决于数据属性hasPrevious -->
            <a
              :class="{ undisable: !data.hasPrevious }"
              href="#"
              title="首页"
              @click.prevent="gotoPage(1)"
            >&lt;&lt;</a
            >
            <a
              :class="{ undisable: !data.hasPrevious }"
              href="#"
              title="前一页"
              @click.prevent="gotoPage(data.current - 1)"
            >&lt;</a
            >
            <a
              v-for="page in data.pages"
              :key="page"
              :class="{
                current: data.current == page,
                undisable: data.current == page
              }"
              :title="'第' + page + '页'"
              href="#"
              @click.prevent="gotoPage(page)"
            >{{ page }}</a
            >
            <a
              :class="{ undisable: !data.hasNext }"
              href="#"
              title="后一页"
              @click.prevent="gotoPage(data.current + 1)"
            >&gt;</a
            >
            <a
              :class="{ undisable: !data.hasNext }"
              href="#"
              title="末页"
              @click.prevent="gotoPage(data.pages)"
            >&gt;&gt;</a
            >
            <div class="clear" />
          </div>
        </div>
  </div>
</template>
<script>
import orderApi from "@/api/order";
export default {
  data(){
    return {
      data: {}
    };
  },
  created() {
    this.initBuyRecord();
  },
  methods: {
    initBuyRecord(){
      orderApi.getOrdersByUid(1,8).then(response => {
        this.data = response.data.data;
      })
    },
    gotoPage(page){
      orderApi.getOrdersByUid(page,8).then(response => {
        this.data = response.data.data;
      })
    }
  }
};
</script>
